<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" >
</head>
<script>
    var ws;
    //target 是地址
    var target = "ws://127.0.0.1:8080/socket";
    function socketOpen() {
        if ('WebSocket' in window) {
            ws = new WebSocket(target);
        } else if ('MozWebSocket' in window) {
            ws = new MozWebSocket(target);
        } else {
            alert('WebSocket is not supported by this browser.');
            return;
        }
    }
</script>
<body>
<button onclick="socketOpen();">启动</button>

</body>
</body>
</html>